package gov.child.web.controller;

import gov.child.service.AjaxService;
import gov.child.service.impl.AjaxServiceImpl;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author fzh
 * @since 2017/9/20
 */
@Controller
@RequestMapping("/asyn")
public class Asynchronous {
    @Autowired
    private AjaxService ajaxService;

    /*-------------------用户注册时Ajax请求--------------------*/



    @GetMapping("/username")
    @ResponseBody
    public JSONObject username(String username) {
        JSONObject json = new JSONObject();
        if (ajaxService.findUsernameFromUser(username)) {
            json.put("status", true);
        } else {
            json.put("status", false);
        }
        return json;
    }

    @GetMapping("/phone")
    @ResponseBody
    public JSONObject phone(String phone) {
        JSONObject json = new JSONObject();
        if (ajaxService.findPhoneFromUser(phone)) {
            json.put("status", true);
        } else {
            json.put("status", false);
        }
        return json;
    }
}
